
use blog_server::user;
use salvo::prelude::*;
use salvo::http::Method;


#[handler]
async fn hello() -> &'static str
{
    "你好哇！"
}


#[tokio::main]
async fn main() {
    println!("Hello, world!");

    blog_server::db::init_rbatis_sqlite("sqlite://./database.db");

    tracing_subscriber::fmt().init();

    let cors_handler = salvo::cors::Cors::new()
        .allow_origin("*")
        .allow_methods(vec![Method::GET, Method::POST, Method::DELETE])
        .into_handler();

    let router = Router::new()
        .hoop(salvo::logging::Logger::new())
        .hoop(cors_handler)
        .get(hello)
        .push(user::router());


    let acceptor = TcpListener::new("127.0.0.1:8080").bind().await;
    Server::new(acceptor).serve(router).await;
}

